<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>波次分单系统</title>
    <!-- ZUI 标准版压缩后的 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/zui/1.8.1/css/zui.min.css">

    <!-- ZUI Javascript 依赖 jQuery -->
    <script src="https://cdn.bootcss.com/zui/1.8.1/lib/jquery/jquery.js"></script>
    <!-- ZUI 标准版压缩后的 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/zui/1.8.1/js/zui.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/zui/1.7.0/lib/datetimepicker/datetimepicker.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/zui/1.7.0/lib/datetimepicker/datetimepicker.min.js"></script>
    <script src="https://w.shidexian.com/data/assets/js/jquery.md5.js" type="text/javascript"></script>
    <script src="https://cdn.bootcss.com/zui/1.8.1/lib/bootbox/bootbox.min.js"></script>
    <link href="https://cdn.bootcss.com/zui/1.8.1/lib/bootbox/bootbox.min.css" rel="stylesheet">
</head>
<body>
<div style="padding: 20px;">
    <ul class="nav nav-tabs">
        <li class="active"><a href="###" data-target="#tab2Content2" data-toggle="tab">工作台</a></li>
        <li><a href="###" data-target="#tab2Content3" data-toggle="tab" onclick="switch_order(2)">拣货单列表</a></li>
        <li style="padding: 9px 15px;float: right;">
            <span id="turename">请登录</span>,  <span style="color: #ff0000;cursor: pointer" onclick="unlogin()">注销</span>
        </li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane fade active in" id="tab2Content2" style="margin-top: 10px">

            <ul class="nav nav-tabs">
                <li class="active"><a href="###" data-target="#tab2Content2_1" data-toggle="tab" onclick="get_Question_List()">问题单</a></li>
                <li><a href="###" data-target="#tab2Content2_2" data-toggle="tab">拣货波次管理</a></li>
                <li><a href="###" data-target="#tab2Content2_3" data-toggle="tab" onclick="load_normal_order()">订单列表</a></li>
            </ul>
            <div class="tab-content">
                <div class="tab-pane fade active in" id="tab2Content2_1">
                    <!--标签页待处理订单 开始-->
                    <div class="panel" style="margin: 10px;">
                        <div class="panel-heading">
                            <div style="overflow: hidden">
                                <div class="input-group" style="width: 280px;float: left;margin: 5px">
                                    <span class="input-group-addon">时间筛选</span>
                                    <input type="text" id="question_date_start" class="form-control form-date" placeholder="起始日期" style="width: 100px;">
                                    <input type="text" id="question_date_end" class="form-control form-date" placeholder="截止日期" style="width: 100px;">
                                </div>
                                <div class="input-group" style="width: 165px;float: left;margin: 5px">
                                    <span class="input-group-addon">问题类型</span>
                                    <select class="form-control" id="question_type" style="width: 100px">
                                        <option value="">全部</option>
                                        <option value="1">缺货</option>
                                        <option value="2">次品</option>
                                        <option value="3">缺货+次品</option>
                                    </select>
                                </div>
                                <div class="input-group" style="width: 165px;float: left;margin: 5px">
                                    <span class="input-group-addon">订单号</span>
                                    <input class="form-control" style="width: 200px;" id="question_order_sn" type="text"/>
                                </div>
                                <div class="input-group" style="float: left;margin: 5px">
                                    <button class="btn btn-primary" type="button" onclick="get_Question_List()">筛选</button>
                                </div>

                            </div>
                        </div>
                        <div class="panel-body">
                            <table class="table table-bordered table-hove">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" onclick="check_all(this,2)"/>序号</th>
                                    <th>订单号</th>
                                    <th>收货人</th>
                                    <th>下单时间</th>
                                    <th>问题商品</th>
                                    <th>提交人</th>
                                    <th>类型</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="question_order_from">
                                <tr>
                                    <td colspan="8">...</td>
                                </tr>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td colspan="13">
                                        <ul class="pager  pager-pills" style="float: right">
                                            <li id="previous_question" class="previous"><a href="javascript:prev_botton(4)">« 上一页</a></li>
                                            <li id="next_question" class="next"><a href="javascript:next_botton(4)">下一页 »</a></li>
                                        </ul>
                                        <ul class="pager" style="float: right">
                                            <li class="next disabled">
                                                <a href="#" style="color: #0c0c0c" id="all_count_question">共 0 项</a>
                                            </li>
                                        </ul>
                                    </td>
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                    <!--标签页待处理订单 结束-->
                </div>
                <div class="tab-pane fade" id="tab2Content2_2">
                    <!--标签页待工作台 开始-->
                    <div class="panel" style="margin: 10px;">
                        <div class="panel-heading">
                            <div style="overflow: hidden">
                                <div class="input-group" style="width: 177px;float: left;margin: 5px">
                                    <span class="input-group-addon">时间筛选</span>
                                    <input onchange="get_company(1)" type="text" id="sorting_date_1" class="form-control form-date" placeholder="配送日期" style="width: 100px;">
                                </div>
                                <div class="input-group" style="width: 215px;float: left;margin: 5px">
                                    <span class="input-group-addon">所属配送商</span>
                                    <select class="form-control" onchange="get_time(1)" style="width: 150px" id="company_id_1">
                                    </select>
                                </div>
                                <div class="input-group" style="width: 185px;float: left;margin: 5px">
                                    <span class="input-group-addon">送达时间</span>
                                    <select onchange="get_area(1)" class="form-control" style="width: 120px" id="sorting_time_1">
                                    </select>
                                </div>
                                <div class="input-group" style="width: 215px;float: left;margin: 5px">
                                    <span class="input-group-addon">配送区域</span>
                                    <select class="form-control" style="width: 150px" id="sorting_area_1">
                                    </select>
                                </div>
                                <div class="input-group" style="width: 165px;float: left;margin: 5px">
                                    <span class="input-group-addon">订单类型</span>
                                    <select class="form-control" style="width: 100px" id="sorting_order_type_1">
                                        <option selected value="">全部</option>
                                        <option value="0">普通</option>
                                        <option value="1">超时免单</option>

                                    </select>
                                </div>
                                <div class="btn-group" style="float: left;margin: 5px">
                                    <button class="btn btn-primary" type="button" onclick="switch_order(1,1)">筛选</button>
                                    <button type="button" class="btn" onclick="set_sorting_num()">设置</button>
                                </div>

                            </div>
                        </div>
                        <div class="panel-body">
                            <div style="overflow: hidden;margin-top: 5px;margin-bottom: 5px;">
                                <div class="btn-group" style="float: left;">
                                    <button type="button" class="btn disabled">全部 <span class="label label-badge" id="picking_num">0</span></button>
                                </div>
                                <div class="btn-group" style="float: right;">
                                    <button type="button" class="btn btn-success disabled" id="action_button_1" onclick="generate_sorting()">生成拣货单 <span class="label label-badge" id="action_num_1">0</span></button>
                                </div>
                            </div>
                            <table class="table table-bordered table-hove">
                                <thead>
                                <tr>
                                    <th><input type="checkbox" onclick="check_all(this,1)"/>订单 ID</th>
                                    <th>订单编号</th>
                                    <th>下单时间</th>
                                    <th>所属划区</th>
                                    <th>所属配送商</th>
                                    <th>期望送达</th>
                                    <th>超时免单</th>
                                </tr>
                                </thead>
                                <tbody id="order_from_picking">
                                <tr>
                                    <td colspan="7" align="center">点击筛选</td>
                                </tr>
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td colspan="8">
                                        <ul class="pager  pager-pills" style="float: right">
                                            <li id="previous_1" class="previous disabled"><a href="javascript:prev_botton(1)">« 上一页</a></li>
                                            <li id="next_1" class="next disabled"><a href="javascript:next_botton(1)">下一页 »</a></li>
                                        </ul>
                                        <ul class="pager" style="float: right">
                                            <li class="next disabled">
                                                <a href="#" style="color: #0c0c0c" id="all_count_picking">共 0 项</a>
                                            </li>
                                        </ul>
                                    </td>
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                    <!--标签页待工作台 结束-->
                </div>
                <div class="tab-pane fade" id="tab2Content2_3">
                    <!--普通订单处理-->
                    <div class="panel" style="margin: 10px;">
                        <div class="panel-heading">
                            <div style="overflow: hidden">
                                <div class="input-group" style="width: 280px;float: left;margin: 5px">
                                    <span class="input-group-addon">时间筛选</span>
                                    <input type="text" id="normal_date_start" class="form-control form-date" placeholder="起始日期" style="width: 100px;">
                                    <input type="text" id="normal_date_end" class="form-control form-date" placeholder="截止日期" style="width: 100px;">
                                </div>
                                <div class="input-group" style="width: 165px;float: left;margin: 5px">
                                    <span class="input-group-addon">订单号</span>
                                    <input class="form-control" style="width: 200px;" type="text" id="normal_order_sn"/>
                                </div>
                                <div class="input-group" style="float: left;margin: 5px">
                                    <button class="btn btn-primary" type="button" onclick="load_normal_order()">筛选</button>
                                </div>
                                <span style="color: red;line-height: 42px;">当前仅可查询 未取消/未配送 的订单</span>
                            </div>
                        </div>
                        <div class="panel-body">
                            <table class="table table-bordered table-hove">
                                <thead>
                                <tr>
                                    <th>序号</th>
                                    <th>订单号</th>
                                    <th>收货人</th>
                                    <th>下单时间</th>
                                    <th>金额</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="normal_order_from">
                                </tbody>
                                <tfoot>
                                <tr>
                                    <td colspan="7">
                                        <ul class="pager  pager-pills" style="float: right">
                                            <li id="previous_normal" class="previous"><a href="javascript:prev_botton(3)">« 上一页</a></li>
                                            <li id="next_normal" class="next"><a href="javascript:next_botton(3)">下一页 »</a></li>
                                        </ul>
                                        <ul class="pager" style="float: right">
                                            <li class="next disabled">
                                                <a href="#" style="color: #0c0c0c" id="all_count_normal">共 0 项</a>
                                            </li>
                                        </ul>
                                    </td>
                                </tr>
                                </tfoot>
                            </table>
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="tab-pane fade" id="tab2Content3">
            <!--标签页待拣货单 开始-->
            <div class="panel" style="margin: 10px;">
                <div class="panel-heading">
                    <div style="overflow: hidden">
                        <div class="input-group" style="width: 177px;float: left;margin: 5px">
                            <span class="input-group-addon">时间筛选</span>
                            <input type="text" id="sorting_date_2" class="form-control form-date" placeholder="配送日期" style="width: 100px;">
                        </div>
                        <div class="input-group" style="width: 215px;float: left;margin: 5px">
                            <span class="input-group-addon">配送区域</span>
                            <select class="form-control" style="width: 150px" id="sorting_area_2">
                            </select>
                        </div>
                        <div class="input-group" style="width: 215px;float: left;margin: 5px">
                            <span class="input-group-addon">所属配送商</span>
                            <select class="form-control" style="width: 150px" id="company_id_2">
                            </select>
                        </div>
                        <div class="input-group" style="width: 215px;float: left;margin: 5px">
                            <span class="input-group-addon">状态</span>
                            <select class="form-control" style="width: 150px" id="sorting_status">
                                <option value="0">全部</option>
                                <option value="1">未拣货</option>
                                <option value="2">已获取</option>
                                <option value="3">拣货中</option>
                                <option value="4">拣货完成</option>
                                <option value="5">取消</option>
                            </select>
                        </div>
                        <div class="input-group" style="float: left;margin: 5px">
                            <button class="btn btn-primary" type="button" onclick="switch_order(2)">筛选</button>
                        </div>

                    </div>
                </div>
                <div class="panel-body">
                    <div style="overflow: hidden;margin-top: 5px;margin-bottom: 5px;">
                        <div class="btn-group" style="float: left;">
                            <button type="button" class="btn disabled">订单总数 <span class="label label-badge" id="sorting_num">0</span></button>
                        </div>
                        <div class="btn-group" style="float: left;margin-left: 15px;">
                            <button type="button" class="btn disabled">未拣货 <span class="label label-badge" id="sorting_original">0</span></button>
                            <button type="button" class="btn disabled">拣货中 <span class="label label-badge" id="sorting_ing">0</span></button>
                            <button type="button" class="btn disabled">拣货完成 <span class="label label-badge" id="sorting_end">0</span></button>
                        </div>
                    </div>
                    <table class="table table-bordered table-hove">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>拣货单号</th>
                            <th>订单数</th>
                            <th>商品数</th>
                            <th>所属划区</th>
                            <th>状态</th>
                            <th>创建时间</th>
                            <th>创建人</th>
                        </tr>
                        </thead>
                        <tbody id="sorting_list">
                        <tr>
                            <td colspan="8" align="center">点击筛选</td>
                        </tr>
                        </tbody>
                        <tfoot>
                        <tr>
                            <td colspan="8">
                                <ul class="pager  pager-pills" style="float: right">
                                    <li id="previous_2" class="previous disabled"><a href="javascript:prev_botton(2)">« 上一页</a></li>
                                    <li id="next_2" class="next disabled"><a href="javascript:next_botton(2)">下一页 »</a></li>
                                </ul>
                                <ul class="pager" style="float: right">
                                    <li class="next disabled">
                                        <a href="#" style="color: #0c0c0c" id="all_count_sorting">共 0 项</a>
                                    </li>
                                </ul>
                            </td>
                        </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
        <!--标签页待拣货单 结束-->
    </div>
</div>
<!--退款对话框 开始-->
<div class="modal fade" id="myModal" style="z-index: 99999">
<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
            <h4 class="modal-title" id="action_title">处理退款</h4>
        </div>
        <div class="modal-body">
            <div id="show_refund_type">
                <p id="action_bar" style="color: #ea644a">选择退款类型</p>
                <select class="form-control form-group" id="refund_type">
                    <option value="1">缺货退款</option>
                    <option value="2">次品退款</option>
                    <option value="3">退货退款</option>
                    <option value="4" id="all_refund">全单退款</option>
                </select>
            </div>
            <div id="show_refund_work_type">
                <p style="color: #ea644a">选择生成工单类型</p>
                <select class="form-control form-group" id="refund_work_type">
                    <option value="1">缺货退款</option>
                    <option value="2">次品退款</option>
                    <option value="3">退货退款</option>
                </select>
            </div>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>商品名称</th>
                    <th>价格</th>
                    <th>总 / 退 / 剩</th>
                    <th width="200">操作</th>
                </tr>
                </thead>
                <tbody id="refund_from">
                </tbody>
            </table>
            <hr/>
            <div class="switch text-left" style="width: 100px;margin-bottom: 10px;">
                <input type="checkbox" id="shipping_fee">
                <label>退运费</label>
            </div>
            <textarea class="form-control" rows="3" id="remark" placeholder="在次输入本次操作的备注"></textarea>
        </div>
        <div class="modal-footer">
            <span style="color: red;float: left">全单退款模式下将自动退运费</span>
            <input type="hidden" value="" id="refund_order_id">
            <button type="button" class="btn btn-default" id="close_button"  data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" id="submit_button" onclick="submit_refund()">确定</button>
        </div>
    </div>
</div>
</div>
<!--退款对话框 结束-->


<!--登录对话框 开始-->
<div class="modal fade" id="login" data-backdrop="static" data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" >用户登录</h4>
            </div>
            <div class="modal-body">
                <p style="color: #ea644a">请在此输入用户名和密码</p>
                <div class="input-group">
                    <span class="input-group-addon">用户名</span>
                    <input type="text" value="" class="form-control" id="username" placeholder="用户名">
                </div>
                <div class="input-group" style="margin-top: 5px;">
                    <span class="input-group-addon">密&#12288;码</span>
                    <input type="password" value="" class="form-control" id="password" placeholder="密码">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" onclick="login()" class="btn btn-primary">确定</button>
            </div>
        </div>
    </div>
</div>
<!--登录对话框 结束-->

<!--设置拣货单订单数量对话框 开始-->
<div class="modal fade" id="set_sorting_num">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title" >设置单个拣货单最多包含订单数量</h4>
            </div>
            <div class="modal-body">
                <p style="color: #ea644a">请在此输入输入一个大于0得数字</p>
                <div class="input-group">
                    <span class="input-group-addon">最多订单数</span>
                    <input type="number" id="sorting_max_num" class="form-control" placeholder="最多订单数" min="1" step="1">
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-primary" onclick="submit_sorting_num()" >确定</button>
            </div>
        </div>
    </div>
</div>
<!--设置拣货单订单数量对话框 结束-->

<!--延迟订单对话框 开始-->
<div class="modal fade" id="delay_from" style="z-index: 99999">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title" >延迟配送</h4>
            </div>
            <div class="modal-body">
                <p>订单号 : <span id="order_sn_delay"></span></p>
                <p>当前期望 : <span id="order_best_time_delay"></span></p>
                <hr/>
                <p style="color: #ea644a">需延迟至</p>

                <div class="input-group">
                    <input type="text" id="delay_date" class="form-control form-date" placeholder="配送日期" style="width: 120px;">
                    <select class="form-control"  style="width: 120px;" id="delay_time">
                    </select>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon">原因</span>
                    <select class="form-control" style="width: 189px;" id="delay_reason">
                    </select>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon">备注</span>
                    <input type="text" class="form-control" id="delay_remark" placeholder="备注" style="width: 189px;">
                </div>
                <hr/>
                <div class="switch text-left" style="margin-bottom: 10px;">
                    <input type="checkbox" id="unSorting">
                    <label>解包（反配货）</label>
                </div>
                <hr/>
                <span style="color: red">如订单已在拣货单中，延迟后此订单将分离原拣货单</span>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="delay_order_id" value="">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-primary" onclick="submit_delay()" >确定</button>
            </div>
        </div>
    </div>
</div>
<!--延迟订单对话框 结束-->
<!--退款对话框 开始-->
<div class="modal fade" id="QuestionModal">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">关闭</span></button>
                <h4 class="modal-title">订单处理</h4>
            </div>
            <div class="modal-body">
                <div style="margin: 10px 0 10px 0">
                    订单号：<span id="orderSn" style="color: red"></span> <span style="color: red;margin-left: 5px;"  id="orderUser"></span>
                </div>
                <table class="table table-bordered">
                    <thead>
                    <tr>
                        <th>商品名称</th>
                        <th>下单数</th>
                        <th>问题数</th>
                        <th>库存/占用/可售</th>
                    </tr>
                    </thead>
                    <tbody id="Question_from">
                    </tbody>
                </table>
                <hr/>
                <div style="margin: 10px 0 10px 0">
                    客户备注：<span id="orderRemark" style="color: red"></span>
                </div>
                <hr/>
                <div style="margin: 10px 0 10px 0;font-weight: bold">操作备注</div>
                <textarea class="form-control" rows="3" id="wx_remark" placeholder="在次输入本次操作的备注"></textarea>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" id="wx_button">无需处理</button>
                <button type="button" class="btn" id="yc_button">延迟订单</button>
                <button type="button" class="btn btn-primary" id="th_button">退货处理</button>
            </div>
        </div>
    </div>
</div>
<!--退款对话框 结束-->
<script>
    $(".form-date").datetimepicker(
        {
            language:  "zh-CN",
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0,
            format: "yyyy-mm-dd"
        });
    window.onload = function(){
        var isChrome = navigator.userAgent.toLowerCase().match(/chrome/) != null;
        if (!isChrome) {
            alert('请使用 Chrome 浏览器访问本页面');
            return;
        }
    }
    window.onbeforeunload=function(e){
        var e = window.event||e;
        e.returnValue=("非本人电脑，离开时请注销账号");
    }

    var login_status = false;   //测试模式 默认已登录
    var user_id = 0;
    var wid = 0;
    var server_url = "http://api.jd.shidexian.com/sortingweb/";
    var bsc_server_url = "http://w.shidexian.com/admin/order.php?app_action=1&act=info&order_id=";
    //var server_url = "http://sdxapi.com/sortingweb/";
    var token = "";
    var page = 1;
    var refund_type_class = 1;
    var question_type;
    var server_info = [
        { "Api 服务器": server_url,"订单服务器": bsc_server_url  }
    ];
    console.table(server_info);
    var day1 = new Date();
    day1.setTime(day1.getTime()-24*60*60*1000*7);
    var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();

    $("#normal_date_start").val(s1);
    $("#question_date_start").val(s1);

    var myDate = new Date();//获取系统当前时间
    var nowDate = myDate.toLocaleDateString(); //获取当前日期
    $("#normal_date_end").val(nowDate.replace(/\//g, "-"));
    $("#question_date_end").val(nowDate.replace(/\//g, "-"));
    $("#sorting_date_2").val(nowDate.replace(/\//g, "-"));

    if(login_status==false){
        if(window.localStorage){
            user_id = localStorage.getItem("user_id");
            token = localStorage.getItem("token");
            wid = localStorage.getItem("wid");
            turename = localStorage.getItem("turename");
            if(user_id>0&&token.length>0&&wid>0){
                $("#turename").html(turename);
                getBaseData();  //获取基本信息 区域 时间 仓库
                login_status = true;
                get_Question_List();
                message("已记住登录，如需退出请点击右上角「 注销 」",true);
                var server_info = [
                    { "用户ID": user_id,"姓名": turename,"TOKEN": token,"仓库ID": wid  }
                ];
                console.table(server_info);
            }else{
                //弹出登录框
                show_login();
            }
        }else{
            //弹出登录框
            console.log("22");
            show_login();
        }
    }

    function show_login() {

        $("#login").modal('show');//窗口
        $("#login").modal({backdrop: 'static', keyboard: false});  //手动开启
    }



    //跳过问题单
    function jump_order(orderId) {
        var remark = $("#wx_remark").val();
        if(remark.length==0){
            message("请填写备注",false);
            return  false;
        }else{
            $.post(server_url+"jumpQuestionOrder", {
                api_token:token,order_id:orderId,userId:user_id,remark:remark
            }, function(result){
                if(result.code==400||result.data=="api_token 不存在或已过期"){
                    unlogin();
                    return false;
                }
                if(result.code==200){
                    message("操作成功",true);
                    get_Question_List();
                    //关闭问题单界面
                    $("#QuestionModal").modal('hide');
                }else{
                    message("操作错误",false)
                }

            });
        }
    }


    //显示问题单处理界面
    function handle_order(orderId,orderSn,contacts) {
        $("#QuestionModal").modal('show');
        //alert(orderId);
        $("#orderUser").html(contacts); //联系人
        $("#wx_remark").val("");    //再次打开清空操作备注
        $.post(server_url+"getOrderGoods", {
            api_token:token,order_id:orderId,userId:user_id,goods_type:1
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }

            //订单号支持点击显示订单列表
            timestamp = Date.parse(new Date())/1000;
            key = "key4token";
            mac = $.md5(key+timestamp);
            order_url = bsc_server_url+orderId+"&time="+timestamp+"&mac="+mac;
            orderSnHtml = "<span style='cursor: pointer;color: green' data-size='fullscreen' data-iframe='"+order_url+"' data-toggle='modal'>"+orderSn+"</span>";
            $("#orderSn").html(orderSnHtml);    //订单号


            var order_overflow = $("#Question_from");
            var htmls ="";
            $.each(result.data.goodsList, function(name, value) {
                console.log(value);
                $("#orderRemark").html(result.data.orderRemark);       //订单备注
                var surplus_num = value.goods_number - value.refund_number;
                var action_text = "";

                if(value.lackNum>0){
                    action_text += "缺货: "+value.lackNum+"<br/>";
                }
                if(value.poorNum>0){
                    action_text += "次品: "+value.poorNum+"<br/>";
                }
                htmls +="<tr>"+
                    "<td style='line-height: 30px;'>"+value.ShowName+"</td>"+
                    "<td style='line-height: 30px;'>"+surplus_num+"</td>"+
                    "<td style='line-height: 30px;'>"+action_text+"</td>"+
                    "<td style='line-height: 30px;'>...下步再搞</td>" +
                    "</tr>"
            });
            if(htmls==""){
                message("无记录",true);
            }
            order_overflow.html(htmls);

            var oDiv = document.getElementById("yc_button");
            oDiv.onclick = function(){
                delay_order(orderId);
            };

            var oDiv = document.getElementById("th_button");
            oDiv.onclick = function(){
                returns_order(orderId,1);
            };
            var oDiv = document.getElementById("wx_button");
            oDiv.onclick = function(){
                //bootbox.confirm("Hello world!",jump_order(orderId));
                bootbox.confirm({
                    message: "确认要关闭此问题单吗？",
                    buttons: {confirm: {label: "确认"}, cancel:{label:"取消"}},
                    callback: function(result) {
                        if(result) {
                            jump_order(orderId);
                        }
                    }
                });


            };

        });
    }

    //根据日期获取配送时间列表
    function get_company(type) {
        var get_data = $("#sorting_date_"+type).val();  //当前日期

        $.post(server_url+"getCompanyList", {
            api_token:token,wid:wid,date:get_data
        }, function(result){

            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }

            var htmls ="<option value=''>请选择</option>";
            if(result.data !=null){
                $.each(result.data, function(name, value) {
                    htmls +="<option value='"+value.id+"'>"+value.lite_name+" 「 "+value.orderNumber+" 」</option>";
                });
            }else{
                message("当天无订单",false);
            }
            $("#company_id_1").html(htmls);
            $("#sorting_time_1").html("");
            $("#sorting_area_1").html("");
            console.log('已加载配送商列表');
        });
    }

    //根据日期获取配送时间列表
    function get_time(type) {
        var get_data = $("#sorting_date_"+type).val();  //配送日期
        var get_company = $("#company_id_"+type).val();  //配送合作商
        if(get_company.length ==0){
            message("请选择配送合作商",false);
            return false;
        }
        $.post(server_url+"getTimeList", {
            api_token:token,wid:wid,date:get_data,company_id:get_company
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            var htmls ="<option value=''>请选择</option>";
            $.each(result.data, function(name, value) {
                htmls +="<option value='"+value.best_time_start+"-"+value.best_time+"'>" +
                    value.bestTimeMsg+" 「 "+value.orderNumber+" 」</option>";
            });
            $("#sorting_time_1").html(htmls);
            $("#sorting_area_1").html("");
            console.log('已加载配送时间');
        });
    }
    //获取区域
    function get_area(type) {
        var get_time = $("#sorting_time_"+type).val(); //配送时间
        var get_data = $("#sorting_date_"+type).val();  //配送日期
        var get_company = $("#company_id_"+type).val();  //配送合作商
        if(get_time.length ==0){
            message("请选择配送时间",false);
            return false;
        }
        $.post(server_url+"getAreaList", {
            api_token:token,wid:wid,date:get_data,time:get_time,company_id:get_company
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            htmls = "";
            $.each(result.data, function(name, value) {
                htmls +="<option value='"+value.zoning_id+"'>"+value.areaName+" 「 "+value.orderNumber+" 」</option>";
            });
            $("#sorting_area_1").html(htmls);
            console.log('已加载配送区域');
        });
    }

    function prev_botton(type) {
        if(page>1){
            page = page-1;
        }
        switch (question_type){
            case 1:
                switch_order(type);
                break;
            case 2:
                switch_order(type);
                break;
            case 3:
                load_normal_order();
                break;
            case 4:
                get_Question_List();
                break;
            default:
                console.error("错误的分页参数");
        }
    }
    function next_botton(type) {
        page = page+1;
        switch (question_type){
            case 1:
                switch_order(type);
                break;
            case 2:
                switch_order(type);
                break;
            case 3:
                load_normal_order();
                break;
            case 4:
                get_Question_List();
                break;
            default:
                console.error("错误的分页参数");
        }
    }
    //退出登录
    function unlogin() {
        localStorage.clear();
        message("已退出登录",true);
        login_status = false;   //测试模式 默认已登录
        user_id = 0;
        wid = 0;
        show_login();
    }

    //登录操作
    function login() {
        var userName = $("#username").val();
        var passWord  = $("#password").val();
        $.post(server_url+"login", {
            userName:userName,passWord:passWord
        }, function(result){
            console.log(result);
            if(result.status=="success"){
                user_id = result.data.userId;
                token = result.data.token;
                wid = result.data.wid;
                turename = result.data.name;
                //写入缓存
                localStorage.setItem("user_id",user_id);
                localStorage.setItem("token",token);
                localStorage.setItem("wid",wid);
                localStorage.setItem("turename",turename);

                $("#turename").html(turename);
                getBaseData();  //获取基本信息 区域 时间 仓库
                $("#login").modal('hide');//窗口
                message('欢迎登录：'+turename,true);
            }else{
                message(result.data,false);
            }
        });
    }









    //获取问题单
    function get_Question_List() {
        var question_date_start = $("#question_date_start").val();
        var question_date_end  = $("#question_date_end").val();
        var question_order_sn = $("#question_order_sn").val();
        question_type = $("#question_type").val();
        //var questionType;

        $.post(server_url+"getQuestionOrder", {
            api_token:token,wid:wid,start_date:question_date_start,question_type:question_type,
            end_date:question_date_end,order_sn:question_order_sn,page:page
        }, function(result){
            //console.log(result);
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            timestamp = Date.parse(new Date())/1000;
            key = "key4token";
            mac = $.md5(key+timestamp);

            var order_overflow = $("#question_order_from");
            $("#all_count_question").html("共 "+result.data.total+" 项");
            var htmls ="";
            $.each(result.data.data, function(name, value) {

                switch (value.freeze_status){
                    case 1:
                        questionType = "缺货";
                        break;
                    case 2:
                        questionType = "次品";
                        break;
                    case 3:
                        questionType = "缺货+次品";
                        break;
                    default:
                        questionType = "未知";
                }

                var newDate = new Date();
                var d = parseInt(value.add_time+28800);
                newDate.setTime(d * 1000);

                order_url = bsc_server_url+value.order_id+"&time="+timestamp+"&mac="+mac;
                htmls +="<tr>"+
                    "<td><input type='checkbox' onclick='check_data(2)' name='order_id_array_2' value='"+value.order_id+"'/>"+value.order_id+"</td>"+
                    "<td style='cursor: pointer;color: green' data-size='fullscreen' data-iframe='"+order_url+"' data-toggle='modal'>"+value.order_sn+"</td>"+
                    "<td>"+value.consignee+" 「 "+value.mobile+" 」</td>"+
                    "<td>"+newDate.toLocaleString()+"</td>" +
                    "<td>"+value.GoodsName+"</td>" +
                    "<td>"+value.QuestionUser+"</td>" +
                    "<td>"+questionType+"</td>" +
                    "<td><a href='javascript:handle_order("+value.order_id+",\""+value.order_sn+"\",\""+value.consignee+" 「 "+value.mobile+" 」\")'>订单处理</a> " +
                    "</tr>"
            });
            if(htmls==""){
                message('无记录',true);
            }
            order_overflow.html(htmls);
            if(result.data.current_page==1){
                $("#previous_question").addClass("disabled");
            }else{
                $("#previous_question").removeClass("disabled");
            }
            if(result.data.current_page==result.data.last_page){
                $("#next_question").addClass("disabled");
            }else{
                $("#next_question").removeClass("disabled");
            }
        });




        //new $.zui.Messager('好了好了，我知道了，不过暂时确实要缓一缓', {icon: 'warning-sign',type:'warning'}).show();
    }


    //提交退款信息
    function submit_refund() {
        var work_type = $("#refund_work_type").val();  //工单类型
        if(refund_type_class != 1){
            var refund_type = $("#refund_type").val();  //退款类型
        }
        //
        var goods_list = new Array(); //需处理得商品列表
        var i = 0;
        $("input[name='refund_num[]']").each(function(){
            var refund_num = $(this).val();
            if(refund_num>0){
                var goods_id = $(this).attr('goods_id');
                var rec_id = $(this).attr('rec_id');
                var goods_sn = $(this).attr('goods_sn');
                var giving = $(this).attr('giving');
                var goods_name = $(this).attr('goods_name');
                var goods_one = new Array();
                var refund_type_select  = $($("select[name='refund_type_select[]']").get(i)).val();
                goods_one['num'] = refund_num;
                goods_one['goods_id'] = goods_id;
                goods_one['rec_id'] = rec_id;
                goods_one['goods_sn'] = goods_sn;
                goods_one['giving'] = giving;
                goods_one['goods_name'] = goods_name;
                goods_one['refund_type_select'] = refund_type_select;
                goods_list.push(goods_one);
            }
            i ++;
        });

        if($('#shipping_fee').is(':checked')) {
            var shippingFee = true;
        }else{
            var shippingFee = false;
        }
        if(goods_list.length==0){
            message('老铁，没填商品啊',false);
        }else{
            $("#submit_button").html('<i class="icon icon-spin icon-spinner-snake"></i> 正在提交数据...').attr('disabled',"true");
            var json = "[";
            $.each(goods_list, function(name, value) {
                json += "{";
                json += '"rec_id":"'+value['rec_id']+'",';
                json += '"goods_name":"'+value['goods_name']+'",';
                json += '"goods_sn":"'+value['goods_sn']+'",';
                json += '"goods_id":"'+value['goods_id']+'",';
                json += '"num":"'+value['num']+'",';
                json += '"giving":"'+value['giving']+'",';
                json += '"refund_type_select":"'+value['refund_type_select']+'"';
                json += "},";
            });
            json = json.substr(0, json.length - 1);
            json += "]";

            console.log("json:"+json);
            //return false;
            $.post(server_url+"setRefundGoods", {
                api_token:token,order_id:$("#refund_order_id").val(),userId:user_id,
                refund_type:refund_type,shippingFee:shippingFee,remark:$("#remark").val(),
                goods_list:json,wid:wid,refundTypeClass:refund_type_class,work_type:work_type
            }, function(result){
                if(result.code==400||result.data=="api_token 不存在或已过期"){
                    unlogin();
                    return true;
                }
                console.log(result);
                if(result.status=="success"){
                    message("已操作",true);
                    if(refund_type_class == 1) {
                        get_Question_List();
                    }else{
                        load_normal_order();
                    }
                    $("#myModal").modal('hide');
                    $("#QuestionModal").modal('hide');
                    $("#submit_button").html('确定').removeAttr("disabled");
                }else{
                    message(result.status,false);
                    $("#submit_button").html('确定').removeAttr("disabled");
                }

            });
        }
    }

    //退款处理
    function returns_order(order_id,goods_type) {
        $.post(server_url+"getOrderGoods", {
            api_token:token,order_id:order_id,userId:user_id,goods_type:goods_type
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            $("#refund_order_id").val(order_id);
            console.log(result);
            if(goods_type==1){
                refund_type_class = 1;  //问题单
                $("#show_refund_type").hide();
                //$("#show_refund_work_type").show();
            }else{
                refund_type_class = 2;  //正常单
                $("#show_refund_type").show();
                //$("#show_refund_work_type").hide();
            }
            if(result.data.qualityStatus==0){
                $("#all_refund").hide();
            }else{
                $("#all_refund").show();
            }

            if(result.data.orderFee==0){
                //禁用运费按钮
                $("#shipping_fee").attr("checked",false).attr("disabled","disabled");
            }else{
                $("#shipping_fee").attr("checked",false).attr("disabled",false);
            }
            var order_overflow = $("#refund_from");
            var htmls ="";
            $.each(result.data.goodsList, function(name, value) {
                console.log(value);
                var surplus_num = value.goods_number - value.refund_number;
                var action_num = value.lackNum + value.poorNum;



                if(value.giving == 1){
                    var good_type = '<span class="label label-badge label-danger">赠</span>';
                }else{
                    var good_type = "";
                }
                if(surplus_num==0||value.giving == 1){
                    if(value.giving == 1){
                        var input_html = "<input goods_id = '"+value.goods_id+"' giving ='"+value.giving+"' goods_name='"+value.goods_name+"' goods_sn='"+value.goods_sn+"' rec_id='"+value.rec_id+"' name='refund_num[]' type='number' id='giving_"+value.goods_id+"' readonly value='0' style='width: 100px;' class='form-control' placeholder='数量'>";
                    }else{
                        var input_html = "<input type='number' readonly value='0' style='width: 100px;' class='form-control' placeholder='数量'>";
                    }
                }else{
                    if(goods_type==0){
                        var input_html = "<div class='input-group'>" +
                            "<span class='input-group-addon'>数量</span>" +
                            "<input onkeyup='change_give("+value.goods_id+",this)' name='refund_num[]' type='number' giving ='"+value.giving+"' goods_name='"+value.goods_name+"' goods_sn='"+value.goods_sn+"' rec_id='"+value.rec_id+"' min='0.1'" +
                            " max='"+surplus_num+"' value='0' style='width: 100px;' class='form-control'" +
                            " placeholder='数量' goods_id = '"+value.goods_id+"'</div>";
                    }else{
                        //问题单处理
                        if(value.lackNum>0&&value.poorNum==0){
                            //缺货
                            var input_html = "<div class='input-group'>" +
                                "<select name='refund_type_select[]' class='form-control' style='width: 110px'><option value='1' selected >缺货退款</option><option value='2'>次品退款</option><option value='3'>退货退款</option></select>" +
                                "<input name='refund_num[]' type='number' giving ='"+value.giving+"' goods_name='"+value.goods_name+"' goods_sn='"+value.goods_sn+"' rec_id='"+value.rec_id+"' min='0.1'" +
                                " max='"+surplus_num+"' value='"+action_num+"' style='width: 70px;' class='form-control'" +
                                " placeholder='数量' goods_id = '"+value.goods_id+"'</div>";
                        }
                        if(value.lackNum==0&&value.poorNum>0){
                            //次品
                            var input_html = "<div class='input-group'>" +
                                "<select name='refund_type_select[]' class='form-control' style='width: 110px'><option value='1'>缺货退款</option><option value='2' selected>次品退款</option><option value='3'>退货退款</option></select>" +
                                "<input name='refund_num[]' type='number' giving ='"+value.giving+"' goods_name='"+value.goods_name+"' goods_sn='"+value.goods_sn+"' rec_id='"+value.rec_id+"' min='0.1'" +
                                " max='"+surplus_num+"' value='"+action_num+"' style='width: 70px;' class='form-control'" +
                                " placeholder='数量' goods_id = '"+value.goods_id+"'</div>";
                        }



                    }
                }
                htmls +="<tr>"+
                    "<td style='line-height: 30px;'>"+value.ShowName+""+good_type+"</td>"+
                    "<td style='line-height: 30px;'>¥ "+value.goods_price+"</td>"+
                    "<td style='line-height: 30px;'>"+value.goods_number+" / "+value.refund_number+" / "+surplus_num+"</td>"+
                    "<td style='line-height: 30px;'>"+input_html+"</td>" +
                    "</tr>"
            });
            if(htmls==""){
                message("无记录",true);
            }
            order_overflow.html(htmls);

        });
        $("#myModal").modal('show');
        $("#remark").val("");   //清空备注框

    }

    function change_give(goodsId,obj) {
        console.log(goodsId);
        var newValue = $(obj).val();
        $("#giving_"+goodsId).val(newValue);
    }
    //提交延迟订单
    function submit_delay() {

        var order_id = $("#delay_order_id").val();  //订单ID
        var delay_date = $("#delay_date").val();    //配送日期
        var delay_time = $("#delay_time").val();    //配送时间
        var delay_reason = $("#delay_reason").val();    //延迟原因
        var delay_remark = $("#delay_remark").val();    //延迟备注
        if($('#unSorting').is(':checked')) {
            var unSorting = 1;    //解包
        }else{
            var unSorting = 0;    //解包
        }

        $.post(server_url+"setOrderDelay", {
            api_token:token,order_id:order_id,delay_date:delay_date,delay_time:delay_time,
            delay_reason:delay_reason,delay_remark:delay_remark,userId:user_id,unSorting:unSorting
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            if(result.status=="success"){
                message("已修改成功",true);
                $("#delay_from").modal('hide');//窗口
                load_normal_order();    //重新载入数据
            }else{
                message(result.status,false);
            }
        });
    }
    //延迟订单
    function delay_order(order_id) {
        $.post(server_url+"getDelayOrderInfo", {
            api_token:token,order_id:order_id
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            $("#order_sn_delay").html(result.data.order_sn);
            $("#order_best_time_delay").html(result.data.best_time);
            $("#delay_order_id").val(result.data.order_id);
            htmls = "";
            $.each(result.data.delay_reason, function(name, value) {
                htmls +=" <option value='"+value+"'>"+value+"</option>";

            });
            $("#delay_reason").html(htmls);
            htmls = "";
            $.each(result.data.delay_time, function(name, value) {
                htmls +=" <option value='"+value.start_time+"-"+value.end_time+"'>"+
                    value.start_time+" - "+value.end_time+"</option>";

            });
            $("#delay_time").html(htmls);
        });
        $("#delay_from").modal('show');
    }
    //载入正常订单列表
    function load_normal_order() {
        var normal_date_start = $("#normal_date_start").val();
        var normal_date_end  = $("#normal_date_end").val();
        var normal_order_sn = $("#normal_order_sn").val();
        question_type=3;
        $.post(server_url+"getNormalOrder", {
            api_token:token,wid:wid,start_date:normal_date_start,
            end_date:normal_date_end,order_sn:normal_order_sn,page:page
        }, function(result){
            console.log(result);
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            timestamp = Date.parse(new Date())/1000;
            key = "key4token";
            mac = $.md5(key+timestamp);

            var order_overflow = $("#normal_order_from");
            $("#all_count_normal").html("共 "+result.data.total+" 项");
            var htmls ="";
            $.each(result.data.data, function(name, value) {

                order_url = bsc_server_url+value.order_id+"&time="+timestamp+"&mac="+mac;

                var newDate = new Date();
                var d = parseInt(value.add_time+28800);
                newDate.setTime(d * 1000);
                htmls +="<tr>"+
                    "<td>"+value.order_id+"</td>"+
                    "<td style='cursor: pointer;color: green' data-size='fullscreen' data-iframe='"+order_url+"' data-toggle='modal'>"+value.order_sn+"</td>"+
                    "<td>"+value.consignee+" 「 "+value.mobile+" 」</td>"+
                    "<td>"+newDate.toLocaleString()+"</td>" +
                    "<td>¥ "+value.order_amount+"</td>" +
                    "<td>"+value.status+"</td>" +
                    "<td><a href='javascript:delay_order("+value.order_id+")'>延迟订单</a> " +
                    " <a href='javascript:returns_order("+value.order_id+",0)'>退货处理</a></td>" +
                    "</tr>"
            });
            if(htmls==""){
                message("无记录",true);
            }
            order_overflow.html(htmls);
            if(result.data.current_page==1){
                $("#previous_normal").addClass("disabled");
            }else{
                $("#previous_normal").removeClass("disabled");
            }
            if(result.data.current_page==result.data.last_page){
                $("#next_normal").addClass("disabled");
            }else{
                $("#next_normal").removeClass("disabled");
            }
        });
    }





    //生成拣货单  1拣货单
    function generate_sorting() {
        message("此功能已暂停使用,请使用移动端获取，将会自动生成拣货单",false);
        return true;
        $("#action_button_1").html('<i class="icon icon-spin icon-spinner-snake"></i> 处理中...').attr('disabled',"true");
        var input_name = "order_id_array_1";
        var chk_value =[];//定义一个数组
        $('input[name='+input_name+']:checked').each(function(){
            chk_value.push($(this).val());
        });
        action_order_id =chk_value.join();
        var company_id = $("#company_id_1").val();  //公司ID
        var area_id = $("#sorting_area_1").val();  //公司ID
        var best_time = $("#sorting_time_1").val();  //公司ID
        var best_date = $("#sorting_date_1").val();  //公司ID
        $.post(server_url+"generateSortingOrder", {
            api_token:token,order_id_list:action_order_id,wid:wid,company_id:company_id,
            area_id:area_id,best_time:best_time,best_date:best_date
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            if(result.code == 200){
                message("已生成",true);
                switch_order(1);
            }else{
                message(result.status,false);
            }
            console.log(result);

            $("#action_button_1").html('生成拣货单 <span class="label label-badge" id="action_num_1">0</span>').removeAttr("disabled");
        });
    }


    //执行筛选订单 type=1 未生成拣货单  2拣货单历史记录
    function switch_order(type) {
        var sorting_area = $("#sorting_area_"+type).val();  //配送区域
        var sorting_time = $("#sorting_time_"+type).val();  //配送时间
        var sorting_order_type = $("#sorting_order_type_"+type).val();  //订单类型 1超时免单 0普通
        var sorting_date = $("#sorting_date_"+type).val();  //订单日期区间
        var company_id = $("#company_id_"+type).val();  //公司ID
        var sorting_status = $("#sorting_status").val();  //拣货单状态
        if(type==1){

            if(sorting_time==null||sorting_date==null||company_id==null){
                message("条件未选择",false);
                return true;
            }


            question_type=1;
            var order_overflow = $("#order_from_picking");
            order_overflow.html("");
            $("#picking_num").html("loading...");
            $("#all_count_picking").html("loading...");
            $.post(server_url+"getOrderPending", {
                api_token:token,sorting_date:sorting_date,
                sorting_order_type:sorting_order_type,sorting_time:sorting_time,
                sorting_area:sorting_area,page:page,wid:wid,company_id:company_id
            }, function(result){
                if(result.code==400||result.data=="api_token 不存在或已过期"){
                    unlogin();
                    return true;
                }
                console.log(result);
                timestamp = Date.parse(new Date())/1000;
                key = "key4token";
                mac = $.md5(key+timestamp);

                $("#picking_num").html(result.data.total);
                $("#all_count_picking").html("共 "+result.data.total+" 项");
                var htmls ="";
                $.each(result.data.data, function(name, value) {
                    order_url = bsc_server_url+value.order_id+"&time="+timestamp+"&mac="+mac;
                    htmls +="<tr>"+
                        "<td><input type='checkbox' onclick='check_data(1)' name='order_id_array_1' value='"+value.order_id+"'/>"+value.order_id+"</td>"+
                        "<td style='cursor: pointer;color: green' data-size='fullscreen' data-iframe='"+order_url+"' data-toggle='modal'>"+value.order_sn+"</td>"+
                        "<td>"+value.add_time+"</td>"+
                        "<td>"+value.wdr_id+"</td>" +
                        "<td>"+value.wid+"</td>" +
                        "<td>"+value.best_time+"</td>" +
                        "<td>"+value.free_single+"</td>" +
                        "</tr>"
                });
                order_overflow.html(htmls);
                if(htmls==""){
                    message("无记录",true);
                }
                if(result.data.current_page==1){
                    $("#previous_1").addClass("disabled");
                }else{
                    $("#previous_1").removeClass("disabled");
                }
                if(result.data.current_page==result.data.last_page){
                    $("#next_1").addClass("disabled");
                }else{
                    $("#next_1").removeClass("disabled");
                }
            });
        }else{
            question_type =2;
            var order_overflow = $("#sorting_list");
            order_overflow.html("");
            $("#sorting_num").html("loading...");
            $("#all_count_sorting").html("loading...");
            $("#sorting_original").html("loading...");
            $("#sorting_ing").html("loading...");
            $("#sorting_end").html("loading...");


            $.post(server_url+"getSortingList", {
                api_token:token,sorting_date:sorting_date,
                sorting_status:sorting_status,
                sorting_area:sorting_area,page:page,wid:wid,company_id:company_id
            }, function(result){
                if(result.code==400||result.data=="api_token 不存在或已过期"){
                    unlogin();
                    return true;
                }
                //console.log(result);
                $("#sorting_num").html(result.data.total);
                $("#all_count_sorting").html("共 "+result.data.total+" 项");
                $("#sorting_original").html(result.data.sorting_original);
                $("#sorting_ing").html(result.data.sorting_ing);
                $("#sorting_end").html(result.data.sorting_end);

                var htmls ="";
                $.each(result.data.data, function(name, value) {
                    htmls +="<tr>"+
                        "<td>"+value.id+"</td>"+
                        "<td>"+value.sorting_sn+"</td>"+
                        "<td>"+value.orderNum+"</td>"+
                        "<td>"+value.goodsNum+"</td>" +
                        "<td>"+value.areaName+"</td>" +
                        "<td>"+value.status+"</td>" +
                        "<td>"+value.ctime+"</td>" +
                        "<td>"+value.cuser+"</td>" +
                        "</tr>"
                });
                if(htmls==""){
                    message("无记录",true);
                }
                order_overflow.html(htmls);
                if(result.data.current_page==1){
                    $("#previous_2").addClass("disabled");
                }else{
                    $("#previous_2").removeClass("disabled");
                }
                if(result.data.current_page==result.data.last_page){
                    $("#next_2").addClass("disabled");
                }else{
                    $("#next_2").removeClass("disabled");
                }
            });
        }

    }
    //打开设置拣货单界面
    function set_sorting_num() {
        $("#set_sorting_num").modal('show');//窗口
        $.post(server_url+"getSortingMaxNum", {
            api_token:token,wid:wid
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            //var obj = JSON.parse(result);
            $("#sorting_max_num").val(result.data);
        });
    }
    //提交拣货单最大订单数
    function submit_sorting_num() {
        var max_num = $("#sorting_max_num").val();
        $.post(server_url+"setSortingMaxNum", {
            api_token:token,max_num:max_num,wid:wid
        }, function(result){
            if(result.code==400||result.data=="api_token 不存在或已过期"){
                unlogin();
                return true;
            }
            if(result.code==200){
                message("已修改成功",true);
                $("#set_sorting_num").modal('hide');//窗口
            }else{
                message("出错了",false);
            }
        });
    }
    //全选按钮
    function check_all(obj,id) {
        var input_name = "order_id_array_"+id;
        if($(obj).is(':checked')) {
            i= 0;
            $('input[name='+input_name+']').each(function() {
                $(this).prop('checked', true);
                i++;
            });
            $("#action_button_"+id).removeClass("disabled");
            $("#action_num_"+id).html(i);
        }else {
            $('input[name='+input_name+']').each(function() {
                $(this).removeAttr('checked');
            });
            $("#action_num_"+id).html(0);
        }
    }
    //单个选框
    function check_data(id) {
        var input_name = "order_id_array_"+id;
        $("#action_num_"+id).html(0);
        $("#action_button_"+id).addClass("disabled");
        i= 0;
        $('input[name='+input_name+']:checked').each(function(){
            $("#action_button_"+id).removeClass("disabled");
            i++;
            return true;
        });
        $("#action_num_"+id).html(i);
    }
    //获取配送区域
    function getBaseData() {
        $.post(server_url+"getBaseData", {api_token:token}, function(result){
            //console.log(result);

            if(result.code==400){
                unlogin();
                return true;
            }


            var htmls ="<option value='0'>全部</option>";
            $.each(result.data.area, function(name, value) {
                htmls +="<option value='"+value.id+"'>"+value.name+"</option>";
            });
            //$("#sorting_area_1").html(htmls);
            $("#sorting_area_2").html(htmls);
            console.log('已加载配送区域');

            var htmls ="<option value='0'>全部</option>";
            $.each(result.data.time, function(name, value) {
                htmls +="<option value='"+value.start_time+"-"+value.end_time+"'>" +
                    ""+value.start_time+" - "+value.end_time+"</option>";
            });
            //$("#sorting_time_1").html(htmls);
            $("#sorting_time_2").html(htmls);
            console.log('已加载配送时间');
            var htmls ="<option value=''>全部</option><option value='0'>自配送</option>";
            $.each(result.data.warehouse, function(name, value) {
                htmls +="<option value='"+value.id+"'>"+value.lite_name+"</option>";
            });
            //$("#company_id_1").html(htmls);
            $("#company_id_2").html(htmls);
            console.log('已加载配送商列表');
            var htmls ="";
            $.each(result.data.refund_work_type, function(name, value) {
                htmls +="<option value='"+value.type_id+"'>" +
                    ""+value.type_name+"</option>";
            });
            $("#refund_work_type").html(htmls);
            console.log('已加载退货工单类型');
        });
    }

    function message(message,type) {
        if(type===true){
            new $.zui.Messager(message, {icon: 'ok-sign',placement: 'center',type:'success'}).show();
        }else{
            new $.zui.Messager(message, {icon: 'warning-sign',placement: 'center',type:'warning'}).show();
        }
    }
</script>
</body>
</html>